package cn.signalpha.modules.com.controller.admin;

import cn.signalpha.common.constant.AppConstant;
import cn.signalpha.core.boot.ctrl.BaseController;
import cn.signalpha.core.mp.support.Condition;
import cn.signalpha.core.mp.support.Query;
import cn.signalpha.core.tool.api.R;
import cn.signalpha.core.tool.utils.Func;
import cn.signalpha.modules.com.dto.WithdrawDTO;
import cn.signalpha.modules.com.entity.Withdraw;
import cn.signalpha.modules.com.service.WithdrawService;
import cn.signalpha.modules.com.vo.WithdrawVO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.Map;

/**
 * 控制器
 *
 * @author signalpha
 */
@RestController
@AllArgsConstructor
@RequestMapping(AppConstant.APPLICATION_USER_NAME + "/admin/withdraw")
@Api(value = "提现", tags = "提现")
public class WithdrawController extends BaseController {

	private final WithdrawService withdrawService;

	@GetMapping("/user/page")
	@ApiOperation(value = "用户分页", notes = "")
	public R<IPage<WithdrawVO>> userPage(@ApiIgnore @RequestParam Map<String, Object> params, Query query) {
		params.put("category", "1");
		return R.data(withdrawService.selectWithdrawUserPage(Condition.getPage(query), params));
	}

	@GetMapping("/seller/page")
	@ApiOperation(value = "商户分页", notes = "")
	public R<IPage<WithdrawVO>> sellerPage(@ApiIgnore @RequestParam Map<String, Object> params, Query query) {
		params.put("category", "2");
		return R.data(withdrawService.selectWithdrawSellerPage(Condition.getPage(query), params));
	}

	@GetMapping("/info")
	@ApiOperation(value = "详情", notes = "")
	public R<Withdraw> info(@RequestParam String id) {
		return R.data(withdrawService.getById(id));
	}

	@PostMapping("/audit")
	@ApiOperation(value = "审核", notes = "")
	public R audit(@RequestBody WithdrawDTO.AuditDTO auditDTO) {
		Func.toLongList(auditDTO.getIds()).forEach(id -> {
			withdrawService.audit(id, auditDTO.getStatus(), auditDTO.getRemark());
		});
		return R.status(true);
	}

}
